package com.javahash.spring.config;


import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;


@Configuration
@PropertySource("classpath:mongodb.properties")


public class MongoConfiguration extends AbstractMongoConfiguration {

    @Autowired
    private Environment environment;

    @Override
    public String getDatabaseName() {
        return environment.getProperty("db.name");
    }

    @Override
    @Bean
    public Mongo mongo() throws Exception {
        String dbHost = environment.getProperty("db.host");
        return new MongoClient(dbHost);
    }


}